<?php
	session_start();
	require_once('site/class/utility.php');
	include("site/pre_header.php");
	if(!$adm)
		die('You don\'t have Permission to view this page!');
?>
<div id="main">
<?php
	include("site/header.php");
        ?>
    <div id="allcontents">
    <?php
	include("site/sideleft.php");
	include("site/sideright.php");
		
	$type = array('announcement','business');
	foreach($type as $a)
	{
		$posts = utility::getAllPosts($a);
?>
	<br>
	<div id="content">
        <h3 align="center"><?php echo ucwords($a);?></h3><br/><br/>
    	<table class="admin-table">
        	<tr>
            	<th style="width:10%;">
                	#
                </th>
                <th style="width:35%;">
                	Title
                </th>
                <th style="width:25%;">
                	Status
                </th>
                <th>
                	Date
                </th>
            </tr>
            <?php
            	foreach($posts as $post)
				{
					$appr = ($post['status']==1?'approve':'unapprove');
					?>	
        		<tr>
                        	
                            <td align="center">
                            	<?php echo $post['id'];?>
                            </td>
                            <td>
                            	<a title="View Post" href="<?php echo $post['urls'].$post['id'].'-'.str_replace(' ','_',$post['name']).'.php';?>" target="_blank"><?php echo ucwords(substr($post['name'],0,50));?></a>
                            </td>
                            <td align="center">
                            	<?php 
									if($adm)
									{
								?>
                                <a href="javascript:void(0);" onclick="action(<?php echo $post['status'].',\''.$a.'\','.$post['id'];?>)" title="<?php echo ($post['status']==1?'Unapprove':'Approve');?>" class="action">
                                	<img class="action" src="site/images/<?php echo $appr;?>.gif"/>
                                </a>
                                <?php
									}
								?>
                                <a href="content.php?type=edit&content_type=<?php echo $a.'&id='.$post['id'];?>" target="_blank" title="edit" class="action">
                                	<img class="action" src="site/images/edit.gif"/>
                                </a>
                                <a href="javascript:void(0);" onclick="action('delete',<?php echo '\''.$a.'\','.$post['id'];?>)" title="delete" class="action">
                                	<img class="action" src="site/images/delete.gif"/>
                                </a>
                            </td>
                            <td>
                            	<?php echo $post['when'];?>
                            </td>
                        </tr>
				 <?php
				 }
				 ?>
        </table>
	</div>   
<?php
	}
        //get users
        $users = utility::getUsers();
?>
        <br/>
        <div id="content">
            <h3 align="center">Users</h3><br/><br/>
        <table class="admin-table">
            <tr>
                <th style="width:10%;">#</th>
                <th style="width:35%;">User Name</th>
                <th style="width:25%;">Status</th>
                <th >Date</th>
            </tr>
            <?php
                //get users
                $users = utility::getUsers();
                foreach($users as $user)
                {
					$appr = ($user['status']==1?'approve':'unapprove');
            ?>
            <tr>
                <td align="center">
                    <?php echo $user['id'];?>
                </td>
                <td>
                    <?php echo ucwords($user['name']);?>
                </td>
                <td align="center">
                    <?php 
						if($adm)
						{
					?>
					<a href="javascript:void(0);" onclick="action(<?php echo $user['status'].',\'user\','.$user['id'];?>)" title="<?php echo ($user['status']==1?'Unapprove':'Approve');?>" class="action">
						<img class="action" src="site/images/<?php echo $appr;?>.gif"/>
					</a>
					<?php
						}
					?>
                    <a href="content.php?type=edit&content_type=<?php echo 'user&id='.$user['id'];?>" target="_blank" title="edit" class="action">
                        <img class="action" src="site/images/edit.gif"/>
                    </a>
                    <a href="javascript:void(0);" onclick="action('delete',<?php echo '\'user\','.$user['id'];?>)" title="delete" class="action">
                        <img class="action" src="site/images/delete.gif"/>
                    </a>
                </td>
                <td>
                    <?php echo $user['when'];?>
                </td>
            </tr>
            <?php
                }
            ?>
        </table>
        </div>
    </div>
<?php          
        include("site/footer.php");
    ?>
</div>
<script type="text/javascript">

</script>